'''
Created on Oct 11, 2012

@author: daeheehan

Modified on Oct 31, 2012
@author: gyucheol
'''

from pprint import pprint
from github3 import login, GitHub
from github import Github
from github import Issue
from github import IssueEvent

import datetime
import dateutil.parser
import time
from pprint import pprint
import sys
from types import *

# Github User information
GITHUB_USER_ID = "booknara"
GITHUB_USER_ID_1 = "booknaratest"
GITHUB_USER_ID_2 = "jangho87"
GITHUB_USER_ID_3 = 'skswhwo'
GITHUB_USER_ID_4 = 'luispigu'

GITHUB_USER_PW = "qwer1234"
GITHUB_USER_PW_1 = "wasd1234"

if __name__ == '__main__':
    pass

g = Github(GITHUB_USER_ID, GITHUB_USER_PW)
print g.rate_limiting, ' request remaining'

# Github Rails Repository information
GITHUB_USER_NAME = "rails"
GITHUB_REPOSITORY_NAME = "rails"

# Rails collaborators information file
COLLABORATORS_FILE = 'rails_collaborators.txt'

# Rails contributors information file
CONTRIBUTORS_FILE = 'rails_contributors.txt'

user = g.get_user(GITHUB_USER_NAME)
repo = user.get_repo(GITHUB_REPOSITORY_NAME)

collaborators_list = []
contributors_list = []

try:
    f_collaborators = open(COLLABORATORS_FILE, 'w')

    for collaborator in repo.get_collaborators():
        print collaborator.login
        f_collaborators.write(collaborator.login + '\n')

#        break
        
    f_collaborators.close()

    f_contributors = open(CONTRIBUTORS_FILE, 'w')

    for contributor in repo.get_contributors():
        print contributor.login
        f_contributors.write(contributor.login + '\n')

#        break

    f_contributors.close()

except Exception as e: 
    print 'The final Exception', e.args[0]

print g.rate_limiting, ' request remaining'

print
print 'Finally the end'
